//
//  PersonalInfoView.swift
//  letusmeet_ios
//
//  Created by Rovo Dev on 2025/1/27.
//

import SwiftUI

struct PersonalInfoView: View {
    let user: UserProfile
    
    private var profileRows: [ProfileRow] {
        [
            ProfileRow(label: "昵称", value: user.nickname),
            ProfileRow(label: "性别", value: user.gender),
            ProfileRow(label: "年龄", value: "\(user.age)岁"),
            ProfileRow(label: "城市", value: user.city),
            ProfileRow(label: "职业", value: user.profession)
        ]
    }
    
    var body: some View {
        VStack(alignment: .leading, spacing: 16) {
            // 标题
            HStack {
                Text("📊")
                    .font(.system(size: 18))
                Text("个人资料")
                    .font(.system(size: 18, weight: .semibold))
                    .foregroundColor(.primary)
            }
            .padding(.horizontal, 16)
            
            // 资料卡片
            VStack(spacing: 0) {
                ForEach(Array(profileRows.enumerated()), id: \.element.id) { index, row in
                    ProfileRowView(
                        row: row,
                        showDivider: index < profileRows.count - 1
                    )
                }
            }
            .background(Color(NSColor.controlBackgroundColor))
            .clipShape(RoundedRectangle(cornerRadius: 12))
            .shadow(color: .black.opacity(0.05), radius: 8, x: 0, y: 2)
        }
    }
}

struct ProfileRow {
    let id = UUID()
    let label: String
    let value: String
}

struct ProfileRowView: View {
    let row: ProfileRow
    let showDivider: Bool
    
    var body: some View {
        VStack(spacing: 0) {
            HStack {
                Text(row.label)
                    .font(.system(size: 16, weight: .medium))
                    .foregroundColor(.secondary)
                    .frame(width: 60, alignment: .leading)
                
                Text(row.value)
                    .font(.system(size: 16))
                    .foregroundColor(.primary)
                
                Spacer()
            }
            .padding(.horizontal, 16)
            .padding(.vertical, 16)
            
            if showDivider {
                Divider()
                    .padding(.leading, 76)
            }
        }
    }
}

#Preview {
    let sampleUser = UserProfile(
        username: "张小明",
        userID: "20240101",
        nickname: "张小明",
        gender: "男",
        age: 28,
        city: "北京",
        profession: "软件工程师"
    )
    
    PersonalInfoView(user: sampleUser)
        .padding()
        .background(Color(NSColor.controlBackgroundColor))
}